package com.zhoutao.blog.seven.model.response;

import lombok.Data;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Data
public class Article {

    private Long id;


    private String title;

    private String avatar;

    private String description;

    private String content;

    private String mkContent;

    private String icon;

    private String keys;

    private Long categoryId;

    private String type;

    private Integer readCount = 12;

    private Integer commentCount = 12;


    /**
     * 发布时间
     */
    private String createdAt = "2022-01-01 12:00:00";

    public int getSize() {
        return this.content.length();
    }

    public String findKeywords() {
        if (this.keys == null || this.keys.trim().length() == 0) {
            return "java,code,blog,opensource";
        }
        String[] tags = this.keys.split(";");
        for (int i = 0; i < tags.length; i++) {
            String tag = tags[i];
            if (tag == null || tag.trim().length() == 0) {
                continue;
            }
            tags[i] = tag.trim();
        }
        return String.join(",", tags);
    }

    public List<String> findTags() {
        if (this.keys == null || this.keys.trim().length() == 0) {
            return Collections.emptyList();
        }
        String[] tags = this.keys.split(";");
        for (int i = 0; i < tags.length; i++) {
            String tag = tags[i];
            if (tag == null || tag.trim().length() == 0) {
                continue;
            }
            tags[i] = tag.trim();
        }
        return Arrays.asList(tags);
    }
}
